*************************************************************************************************************************
****************************** EXTREMISM AND TERRORISM: REBEL GOALS AND TACTICS IN CIVIL WARS ***************************
******************************* RENANAH MILES JOYCE AND PAGE FORTNA *****************************************************
*********************************** PERSPECTIVES ON POLITICS [2024] *****************************************************
*************************************************************************************************************************
																																		
clear

cap ssc install estout
cap ssc install parmest

use "ReplicationData.dta"																			

*************************************************************************************************************************
*********************** DATA PREP ***************************************************************************************
*************************************************************************************************************************
																							
*** Recode missing 
replace ideology =. if ideology == -99 
replace identitystatus =. if identitystatus == -99

*** Create dummy for major identity status change goals
gen id_major = 1 if identitystatus == 2
replace id_major = 0 if identitystatus < 2

*** Create dummy for secession goals
gen secession = 1 if borders == 2 | borders == 1 & independence == 1
replace secession = 0 if borders == 0 | borders == 1 & independence == 0

*** Create territorial size variables*******

*** Create dummy for < state conflicts
gen less_state = 1 if govtInc == 0 & transnational != 1
replace less_state = 0 if govtInc == 1 | transnational == 1

*** Create dummy for full state conflicts
gen full_state = 1 if govtInc == 1 & transnational != 1
replace full_state = 0 if govtInc == 0 | transnational == 1 

*** Create dummy for > state conflicts
gen mult_state = 1 if transnational == 1
replace mult_state = 0 if transnational != 1

*** Create dummy for pooled extremism variable
gen extreme = 1 if ideology == 1 | id_major == 1 | secession == 1
replace extreme = 0 if ideology != 1 & id_major != 1 & secession != 1

*** Create lagged variables
sort dyadid year
by dyadid: gen km_a_lag1 = L1.km_a
by dyadid: gen rebstrength_lag1 = L1.rebstrength
by dyadid: gen mobcap_lag1 = L1.mobcap
by dyadid: gen war_lag1 = L1.war

*** Round dv
replace km_a=round(km_a)  								

*** Label variables for analysis 																											
label var ideology "Transform system (ideology)"
label var secession "Secession"
label var id_major "Transform system (identity)"
label var xpolity_int_lag1 "Democracy"
label var finances_lag1 "Rebel financing"
label var rebstrength_lag1 "Rebel strength"
label var mobcap_lag1 "Popular support"
label var war_lag1 "Conflict intensity"
label var EPRethnic "Ethnic conflict"
label var mult_groups "Multiple groups"
label var coldwar "Cold War"
label var full_state "Aim: full state"
label var mult_state "Aim: multiple states"
label var km_a "Terrorism fatalities"
label var tm_a "Terrorism attacks"
label var km_a_lag1 "Terrorism fatalities (t-1)"
label var conflictage "Conflict duration"
label var extreme "Extreme aim"
label var lnpop "ln(population)"
label var confstartdate "conflict start date"								

*** Treat as panel data
xtset dyadid year 

*** Drop observations for analysis 
drop if year ==. /* drop conflicts and dyads that exit the data before 1970 */
drop if dyadid == 360 /* drop al-Qaeda-US dyad */
drop if dyadid == 643 /* drop Hezbollah-Israel dyad */
drop if in_ucdp != 1


*************************************************************************************************************************
*********************** MAIN DATA ANALYSES ******************************************************************************				
*************************************************************************************************************************

**********************************************************************
*********** Pooled Model (Table 1 & Figure 3) ************************
**********************************************************************

zinb km_a i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances ///
lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4, inflate (i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_pooled

estout zinb_pooled using table1_pooled.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.extreme Extremeaim xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport 1.mult_groups ///
Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)

// Average marginal effects
margins, dydx(extreme xpolity_int_lag1 rebstrength mobcap mult_groups war EPRethnic finances ///
lnpop coldwar) // marginal effects for count model
marginsplot, horizontal scheme(s1mono) recast(scatter) xline(0, lcolor(red)) xscale(range()) yscale(reverse) title("") ///
	ylabel(1 "Extreme aim" 2 "Democracy" 3 "Rebel strength" 4 "Popular support" 5 "Multiple groups" ///
	6 "Conflict intensity" 7 "Ethnic conflict" 8 "Rebel financing" 9 "Population" 10 "Cold War" ) ///
	xtitle("(A) Predicted # Fatalities", size(12pt)) name(count_pooled, replace)

margins, dydx(extreme xpolity_int_lag1 rebstrength mobcap mult_groups war EPRethnic finances ///
lnpop coldwar) predict(pr) // marginal effects for inflate model
marginsplot, horizontal scheme(s1mono) recast(scatter) xline(0, lcolor(red)) xscale(range()) yscale(reverse) ytitle("") title("") ///
	ylabel(1 "Extreme aim" 2 "Democracy" 3 "Rebel strength" 4 "Popular support" 5 "Multiple groups" ///
	6 "Conflict intensity" 7 "Ethnic conflict" 8 "Rebel financing" 9 "Population" 10 "Cold War" ) ///
	xtitle("(B) Pr(# Fatalities = 0)", size(12pt)) name(inflate_pooled, replace) 
	
graph combine count_pooled inflate_pooled, scheme(s1mono) 


**********************************************************************
*********** Conflicts over Government (Table 2 & Figure 4) ***********
**********************************************************************

zinb km_a i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic ///
i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==1, inflate (i.ideology i.id_major ///
xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 ///
i.GTD3 i.GTD4) vce (cluster conflictid) nolog  
est sto zinb_gov

estout zinb_gov using table2_gov.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.ideology Ideology 1.id_major Identity xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport ///
1.mult_groups Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)

// Average marginal effects
margins, dydx(ideology id_major xpolity_int_lag1 rebstrength mobcap mult_groups war EPRethnic ///
finances lnpop coldwar) // marginal effects for count model
marginsplot, horizontal scheme(s1mono) recast(scatter) xline(0, lcolor(red)) xscale(range()) yscale(reverse) ///
    title("") ylabel(1 "Transform (ideology)" 2 "Transform (identity)" 3 "Democracy" 4 "Rebel strength" ///
	 5 "Popular support" 6 "Multiple groups" 7 "Conflict intensity" 8 "Ethnic conflict" 9 "Rebel financing" /// 
	 10 "Population" 11 "Cold War") xtitle("(A) Predicted # Fatalities", size(12pt)) name(count_gov, replace)
	
margins, dydx(ideology id_major xpolity_int_lag1 rebstrength mobcap mult_groups war EPRethnic ///
finances lnpop coldwar) predict(pr) // marginal effects for inflate model
marginsplot, horizontal scheme(s1mono) recast(scatter) xline(0, lcolor(red)) xscale(range()) yscale(reverse) ytitle("") ///
    title("") ylabel(1 "Transform (ideology)" 2 "Transform (identity)" 3 "Democracy" 4 "Rebel strength" ///
	 5 "Popular support" 6 "Multiple groups" 7 "Conflict intensity" 8 "Ethnic conflict" 9 "Rebel financing" /// 
	 10 "Population" 11 "Cold War") xtitle("(B) Pr(# Fatalities = 0)", size(12pt)) name(inflate_gov, replace)

graph combine count_gov inflate_gov, scheme(s1mono) 
	

**********************************************************************
*********** Conflicts over Territory (Table 3 & Figure 5) ************
**********************************************************************

zinb km_a i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==0, inflate (i.secession xpolity_int_lag1 rebstrength mobcap ///
i.mult_groups i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog  
est sto zinb_ter

estout zinb_ter using table3_ter.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) varlabels (1.secession ///
Secession xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport 1.mult_groups Multiplegroups ///
1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)

// Average marginal effects
margins, dydx(secession xpolity_int_lag1 rebstrength mobcap mult_groups war EPRethnic finances ///
lnpop coldwar) // marginal effects for count model
marginsplot, horizontal scheme(s1mono) recast(scatter) xline(0, lcolor(red)) xscale(range()) yscale(reverse) title("") ///
	ylabel(1 "Secession" 2 "Democracy" 3 "Rebel strength" 4 "Popular support" 5 "Multiple groups" ///
	6 "Conflict intensity" 7 "Ethnic conflict" 8 "Rebel financing" 9 "Population" 10 "Cold War" ) ///
	xtitle("(A) Predicted # Fatalities", size(12pt)) name(count_ter, replace)

margins, dydx(secession xpolity_int_lag1 rebstrength mobcap mult_groups war EPRethnic finances ///
lnpop coldwar) predict(pr) // marginal effects for inflate model
marginsplot, horizontal scheme(s1mono) recast(scatter) xline(0, lcolor(red)) xscale(range()) yscale(reverse) ytitle("") title("") ///
	ylabel(1 "Secession" 2 "Democracy" 3 "Rebel strength" 4 "Popular support" 5 "Multiple groups" ///
	6 "Conflict intensity" 7 "Ethnic conflict" 8 "Rebel financing" 9 "Population" 10 "Cold War" ) ///
	xtitle("(B) Pr(# Fatalities = 0)", size(12pt)) name(inflate_ter, replace) 
	
graph combine count_ter inflate_ter, scheme(s1mono) 

	   
*************************************************************************************************************************
*************************  SUPPLEMENTAL MATERIALS  **********************************************************************
*************************************************************************************************************************

*** Correlation matrices of key variables were created with R. Refer to read.me file for R code and data file ***							

*** Summary statistics of key variables (main analyses and robustness tests)
sum km_a ideology id_major secession xpolity_int rebstrength mobcap mult_groups war EPRethnic finances lnpop coldwar ///
GTD2 GTD3 GTD4 full_state mult_state tm_a km_e k_a conflictage FORGEideology FORGEgoalindep 

tabstat km_a, by(sideb) stat(sum)
	  

**********************************************************************************************************************
*********************** ROBUSTNESS TESTS: ALT MEASURES OF TERRORISM  *************************************************           
**********************************************************************************************************************

*** Round alt measures of dv
replace km_e=round(km_e)  
replace k_a=round(k_a) 

**********************************************************************
***** Using terror attacks DV (Table A2) *****************************																								
**********************************************************************

*** Model 1 pooled conflicts
zinb tm_a i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4, inflate (i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_tm_a_pooled

estout zinb_tm_a_pooled using tableA2_pooled.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.extreme Extremeaim xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport 1.mult_groups ///
Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)
	   
*** Model 2 conflicts over government
zinb tm_a i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic ///
i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==1, inflate (i.ideology i.id_major ///
xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_tm_a_gov

estout zinb_tm_a_gov using tableA2_gov.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) varlabels (1.ideology ///
Ideology 1.id_major Identity xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport 1.mult_groups Multiplegroups ///
1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)
	  
*** Model 3 conflicts over territory
zinb tm_a i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==0, inflate (i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_tm_a_ter

estout zinb_tm_a_ter using tableA2_ter.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) varlabels (1.secession ///
Secession xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport 1.mult_groups Multiplegroups ///
1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)

	   
**********************************************************************
***** Using E version of TAC (Table A3) ******************************
**********************************************************************

*** Model 1 pooled conflicts
zinb km_e i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4, inflate (i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war ///
i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_km_e_pooled

estout zinb_km_e_pooled using tableA3_pooled.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.extreme Extremeaim xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport 1.mult_groups ///
Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)
	   
*** Model 2 conflicts over government
zinb km_e i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==1, inflate (i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap ///
i.mult_groups i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_km_e_gov

estout zinb_km_e_gov using tableA3_gov.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.ideology Ideology 1.id_major Identity xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap ///
Popularsupport 1.mult_groups Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing ///
lnpop Population 1.coldwar ColdWar)
	  
*** Model 3 conflicts over territory
zinb km_e i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==0, inflate (i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_km_e_ter

estout zinb_km_e_ter using tableA3_ter.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) varlabels (1.secession ///
Secession xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport 1.mult_groups Multiplegroups ///
1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)
	   
	   
**********************************************************************
*** Using "least restrictive" fatalities version of TAC (Table A4) ***
**********************************************************************

*** Model 1 pooled conflicts
zinb k_a i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4, inflate (i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_k_a_pooled

estout zinb_k_a_pooled using tableA4_pooled.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) varlabels (1.extreme ///
Extremeaim xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport 1.mult_groups Multiplegroups ///
1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)
	   
*** Model 2 conflicts over government
zinb k_a i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==1, inflate (i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap ///
i.mult_groups i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_k_a_gov

estout zinb_k_a_gov using tableA4_gov.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) varlabels (1.ideology ///
Ideology 1.id_major Identity xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport 1.mult_groups Multiplegroups ///
1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)
	  
*** Model 3 conflicts over territory
zinb k_a i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==0, inflate (i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_k_a_ter

estout zinb_k_a_ter using tableA4_ter.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) varlabels (1.secession ///
Secession xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport 1.mult_groups Multiplegroups ///
1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)	   

	   
**********************************************************************************************************************
*********************** ROBUSTNESS TESTS: ADDITIONAL CONTROLS  *******************************************************
**********************************************************************************************************************

**********************************************************************
***** Adding lagged DV (Table A5) ************************************
**********************************************************************

*** Model 1 pooled conflicts
zinb km_a i.extreme km_a_lag1 xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4, inflate (i.extreme km_a_lag1 xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_lagdv_pooled

estout zinb_lagdv_pooled using tableA5_pooled.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.extreme Extremeaim km_a_lag1 Fatalitieslagged xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap ///
Popularsupport 1.mult_groups Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing ///
lnpop Population 1.coldwar ColdWar)

*** Model 2 government conflicts
zinb km_a i.ideology i.id_major km_a_lag1 xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==1, inflate (i.ideology i.id_major km_a_lag1 xpolity_int_lag1 rebstrength mobcap ///
i.mult_groups i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_lagdv_gov

estout zinb_lagdv_gov using tableA5_gov.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.ideology Ideology 1.id_major Identity km_a_lag1 Fatalitieslagged xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap ///
Popularsupport 1.mult_groups Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing ///
lnpop Population 1.coldwar ColdWar)	   
	  
*** Model 3 
zinb km_a i.secession km_a_lag1 xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==0, inflate (i.secession km_a_lag1 xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_lagdv_ter

estout zinb_lagdv_ter using tableA5_ter.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.secession Secession km_a_lag1 Fatalitieslagged xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap ///
Popularsupport 1.mult_groups Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing ///
lnpop Population 1.coldwar ColdWar)
	   

**********************************************************************
***** Adding conflict duration (Table A6) ****************************
**********************************************************************

*** Model 1 pooled conflicts
zinb km_a i.extreme conflictage xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4, inflate (i.extreme conflictage xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_age_pooled

estout zinb_age_pooled using tableA6_pooled.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.extreme Extremeaim conflictage Conflictduration xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap ///
Popularsupport 1.mult_groups Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing ///
lnpop Population 1.coldwar ColdWar)

*** Model 2 government conflicts
zinb km_a i.ideology i.id_major conflictage xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==1, inflate (i.ideology i.id_major conflictage xpolity_int_lag1 rebstrength mobcap ///
i.mult_groups i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_age_gov

estout zinb_age_gov using tableA6_gov.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.ideology Ideology 1.id_major Identity conflictage Conflictduration xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap ///
Popularsupport 1.mult_groups Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing ///
lnpop Population 1.coldwar ColdWar)
	   
*** Model 3 
zinb km_a i.secession conflictage xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==0, inflate (i.secession conflictage xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_age_ter

estout zinb_age_ter using tableA6_ter.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.secession Secession conflictage Conflictduration xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap ///
Popularsupport 1.mult_groups Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing ///
lnpop Population 1.coldwar ColdWar)
	   

**********************************************************************************************************************
*********************** ROBUSTNESS TEST: DROPPING ETHNIC CONFLICT CONTROL  (TABLE A7) ********************************
**********************************************************************************************************************

*** Model 1 pooled conflicts
zinb km_a i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4, inflate (i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_no_ethnic_pooled

estout zinb_no_ethnic_pooled using tableA7_pooled.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.extreme Extremeaim xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap ///
Popularsupport 1.mult_groups Multiplegroups 1.war Conflictintensity 1.finances Rebelfinancing ///
lnpop Population 1.coldwar ColdWar)

*** Model 2 government conflicts
zinb km_a i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==1, inflate (i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap /// 
i.mult_groups i.war i.finances  lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_no_ethnic_gov

estout zinb_no_ethnic_gov using tableA7_gov.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.ideology Ideology 1.id_major Identity xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap ///
Popularsupport 1.mult_groups Multiplegroups 1.war Conflictintensity 1.finances Rebelfinancing ///
lnpop Population 1.coldwar ColdWar)
	   
*** Model 3 territory conflicts
zinb km_a i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==0, inflate (i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_no_ethnic_ter

estout zinb_no_ethnic_ter using tableA7_ter.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.secession Secession xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport ///
1.mult_groups Multiplegroups 1.war Conflictintensity 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)
	
	   
**********************************************************************************************************************
*********************** ROBUSTNESS TESTS: MULTIPLE IMPUTATION (TABLE A8)  ********************************************
**********************************************************************************************************************

*** Refer to Replication_mi.do for multiple imputation code used to produce Table A8 ***	

**********************************************************************************************************************
*********************** ROBUSTNESS TESTS: GOAL CHANGE > 1 (Table A9) *************************************************
**********************************************************************************************************************

*** Model 1 pooled conflicts
zinb km_a i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if goalschange < 2, inflate (i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_goalschange_pooled

estout zinb_goalschange_pooled using tableA9_pooled.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.extreme Extremeaim xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport 1.mult_groups ///
Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)
	   
*** Model 2 conflicts over government
zinb km_a i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==1 & goalschange < 2, inflate (i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap ///
i.mult_groups i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_goalschange_gov

estout zinb_goalschange_gov using tableA9_gov.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.ideology Ideology 1.id_major Identity xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap ///
Popularsupport 1.mult_groups Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing ///
lnpop Population 1.coldwar ColdWar)
	  
*** Model 3 conflicts over territory
zinb km_a i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==0 & goalschange < 2, inflate (i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_goalschange_ter

estout zinb_goalschange_ter using tableA9_ter.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) varlabels (1.secession ///
Secession xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport 1.mult_groups Multiplegroups ///
1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)


**********************************************************************************************************************
*********************** ROBUSTNESS TEST: NEGATIVE BINOMIAL MODEL SPECIFICATION (Table A10) ***************************
**********************************************************************************************************************

*** Model 1 pooled conflicts
nbreg km_a i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4, vce (cluster conflictid) nolog 
est sto nb_pooled

estout nb_pooled using tableA10_pooled.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) varlabels (1.extreme Extremeaim ///
xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport 1.mult_groups Multiplegroups ///
1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)
	
*** Model 2 conflicts over government
nbreg km_a i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==1, vce (cluster conflictid) nolog 
est sto nb_gov

estout nb_gov using tableA10_gov.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.ideology Ideology 1.id_major Identity xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport ///
1.mult_groups Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)
	  
*** Model 3 conflicts over territory
nbreg km_a i.secession xpolity_int_lag1 rebstrength mobcap i.mult_group i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==0, vce (cluster conflictid) nolog 
est sto nb_ter

estout nb_ter using tableA10_ter.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.secession Secession xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport ///
1.mult_groups Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)
	   
	   
**********************************************************************************************************************
*********************** ROBUSTNESS TEST: USING FORGE (Table A11) *****************************************************
**********************************************************************************************************************

*** Correlation between FORGE ideology variable and RED ideology
cor FORGEideology ideology if govtInc==1 
	   
*** Correlation between FORGE independence variable and RED secession
cor FORGEgoalindep secession if govtInc==0 

*** Model 2 government conflicts using FORGEideology
zinb km_a i.FORGEideology i.id_major xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==1, inflate (i.FORGEideology i.id_major xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_FORGE_gov

estout zinb_FORGE_gov using tableA11_gov.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.FORGEideology FORGEIdeology 1.id_major Identity xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport ///
1.mult_groups Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)

*** Model 3 territory conflicts using FORGEgoalindep
zinb km_a i.FORGEgoalindep xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==0, inflate (i.FORGEgoalindep xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_FORGE_ter

estout zinb_FORGE_ter using tableA11_ter.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.FORGEgoalindep FORGEIndependence xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport ///
1.mult_groups Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)
	   
**********************************************************************************************************************
******************** TESTING ALTERNATIVE CONCEPTION OF EXTREMISM: TERRITORIAL EXTENT (Table A12)  ********************
**********************************************************************************************************************

zinb km_a i.full_state i.mult_state xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4, inflate (i.full_state i.mult_state xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_geoscope

estout zinb_geoscope using tableA12.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.full_state Fullstate 1.mult_state Multiplestates xpolity_int_lag1 Democracy rebstrength Rebelstrength mobcap Popularsupport ///
1.mult_groups Multiplegroups 1.war Conflictintensity 1.EPRethnic Ethnicconflict 1.finances Rebelfinancing lnpop Population 1.coldwar ColdWar)

// Average marginal effects     
margins, dydx(full_state mult_state xpolity_int_lag1 rebstrength mobcap mult_groups war EPRethnic finances lnpop coldwar) // marginal effects for count model
marginsplot, horizontal scheme(s1mono) recast(scatter) xline(0, lcolor(red)) xscale(range()) yscale(reverse) title("") ///
	ylabel(1 "Aim: full state" 2 "Aim: multiple states" 3 "Democracy" 4 "Rebel strength" 5 "Popular support" ///
	6 "Multiple groups" 7 "Conflict intensity" 8 "Ethnic conflict" 9 "Rebel financing" 10 "Population" 11 "Cold War") ///
	xtitle("(A) Predicted # Fatalities", size(12pt)) name(count_geoscope, replace)

margins, dydx(full_state mult_state xpolity_int_lag1 rebstrength mobcap mult_groups war EPRethnic finances lnpop coldwar) predict(pr) // marginal effects for inflate model
marginsplot, horizontal scheme(s1mono) recast(scatter) xline(0, lcolor(red)) xscale(range()) yscale(reverse) ytitle("") ///
    title("") ylabel(1 "Aim: full state" 2 "Aim: multiple states" 3 "Democracy" 4 "Rebel strength" 5 "Popular support" ///
	6 "Multiple groups" 7 "Conflict intensity" 8 "Ethnic conflict" 9 "Rebel financing" 10 "Population" 11 "Cold War") ///
	xtitle("(B) Pr(# Fatalities = 0)", size(12pt)) name(inflate_geoscope, replace)  
	
graph combine count_geoscope inflate_geoscope, scheme(s1mono) 
   

**********************************************************************************************************************
*********************** OTHER ROBUSTNESS TESTS (NOT REPORTED IN SUPP MATERIALS) **************************************
**********************************************************************************************************************

**********************************************************************
*********** Excluding coups ******************************************
**********************************************************************

*** Model 1	
zinb km_a i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if coup !=1, inflate (i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 

*** Model 2 
zinb km_a i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==1 & coup !=1, inflate (i.ideology i.id_major xpolity_int_lag1 rebstrength ///
mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 

*** Model 3 
zinb km_a i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==0 & coup !=1, inflate (i.secession xpolity_int_lag1 rebstrength mobcap ///
i.mult_groups i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
	   

**********************************************************************
*********** Clustered SE by country & dyadid *************************
**********************************************************************

*** Clustered SE by country
*** Model 1	  
zinb km_a i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4, inflate (i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster ccode) nolog 

*** Model 2
zinb km_a i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==1, inflate (i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap ///
i.mult_groups i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster ccode) nolog 

*** Model 3 
zinb km_a i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==0, inflate (i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster ccode) nolog 


*** Clustered SE by dyadid
*** Model 1	  
zinb km_a i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4, inflate (i.extreme xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster dyadid) nolog 

*** Model 2
zinb km_a i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==1, inflate (i.ideology i.id_major xpolity_int_lag1 rebstrength mobcap ///
i.mult_groups i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster dyadid) nolog 

*** Model 3 
zinb km_a i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups i.war i.EPRethnic i.finances lnpop ///
i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==0, inflate (i.secession xpolity_int_lag1 rebstrength mobcap i.mult_groups ///
i.war i.EPRethnic i.finances lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster dyadid) nolog 


clear
